In PL/SQL, a declaration is a statement that defines a variable, constant, cursor, or user-defined data type. A declaration is used to allocate memory and set up the properties of the object being declared.
Here’s an example of declaring a variable in PL/SQL:
DECLARE quantity INTEGER := 10; BEGIN -- Code to use the quantity variable END;
In the example above, we declared a variable named “quantity” with an initial value of 10. We can then use this variable in the code block between the BEGIN
and END
statements.
Defining in PL/SQL refers to creating a new object, such as a function or procedure, that can be executed later. The object’s code is defined within a block of code using the CREATE
statement. Here’s an example of defining a procedure in PL/SQL:
CREATE OR REPLACE PROCEDURE calculate_salary (emp_id IN NUMBER) IS salary NUMBER; BEGIN -- Code to calculate salary based on emp_id DBMS_OUTPUT.PUT_LINE('Salary is ' || salary); END;
In the example above, we defined a procedure named calculate_salary
that takes an employee ID as a parameter. The code within the procedure calculates the salary based on the employee ID and then displays the result using the DBMS_OUTPUT.PUT_LINE
statement. We can then execute this procedure later using a separate PL/SQL block or from another program.
Apply for PL/SQL Certification
https://www.vskills.in/certification/certified-pl-sql-developer